package com.trace.app.controller;


import com.trace.app.entity.Cart;
import com.trace.app.entity.ResponseResult;
import com.trace.app.service.CartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Cart)表控制层
 *
 * @author lionkliu
 * @since 2024-04-02 12:36:42
 */
@RestController
@RequestMapping("cart")
public class CartController {

    @Resource
    private CartService cartService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return cartService.selectPage(pageNum, pageSize);
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return cartService.selectOne(id);
    }

    @GetMapping("/user/{id}")
    public ResponseResult getByUserId(@PathVariable Integer id) {
        return cartService.getByUserId(id);
    }


    @PostMapping
    public ResponseResult insert(@RequestBody Cart cart) {
        return cartService.insertOne(cart);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Cart cart) {
        return cartService.updateOne(cart);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return cartService.deleteById(id);
    }

}
